home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-05 | 1.7 KB | 70 lines | [TEXT/KEEN] |
- #$ClipMultiToInline: change /*...*/ comment to
- # one-line style // comments. Usage: run this hAWK program,
- # Copy the full comment, wait for the menu bar flash,
- # then Paste. NOTE does only one comment at a time.
-
- BEGIN {
- clipCharsToWatch = 32;
- while (1) # run until <Command><period>...
- {
- # see if clipboard has changed
- if ((newClip = getclip(clipCharsToWatch)) != oldClip)
- {
- oldClip = newClip;
- # a comment start is used as the trigger
- if (index(newClip, "/*"))
- ChangeComment()
- }
- }
- }
-
- function ChangeComment( fullClip, numLines, lines, outClip, out, i, addReturn)
- {
- fullClip = getclip(); # gets calling editor's private clip
- numLines = split(fullClip, lines, "\r");
- # with "split", the last line will be empty if the last
- # character copied was a return.
- if (lines[numLines] == "")
- {
- --numLines;
- addReturn = 1;
- }
- else
- addReturn = 0;
- # Put lines to out, altering comment form
- for (i = 1; i <= numLines; ++i)
- {
- # determine leading white space (RLENGTH)
- match(lines[i], /^[ \t]+/);
- if (i == 1)
- {
- sub(/\/\*[ ]?/, "", lines[i]);
- }
- if (i == numLines)
- {
- sub(/[ ]?\*\//, "", lines[i]);
- }
- if (RLENGTH >= 1 && RSTART == 1)
- {
- if (i < numLines || addReturn)
- out = out substr(lines[i], 1, RLENGTH) "// " substr(lines[i], RLENGTH+1) "\r";
- else
- out = out substr(lines[i], 1, RLENGTH) "// " substr(lines[i], RLENGTH+1);
- }
- else
- {
- if (i < numLines || addReturn)
- out = out "// " lines[i] "\r";
- else
- out = out "// " lines[i];
- }
- }
-
- # send the result back to the calling editor's clip
- putclip(out);
- # update "oldClip"
- oldClip = substr(out, 1, 32);
- # flash menu bar to signal something happened
- beep(0);
- }
-